#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <semaphore.h>

sem_t *sem;
char buff[100];
void *write_func(void *arg){

    strcpy(buff,"hello GEM");
    sem_post(sem);
    printf("writer线程写入数据: hello GEM.. \n");
    return NULL;

}

void *read_func(void *arg){
    sem_wait(sem);
    printf("reader线程读取数据: %s\n",buff);
    return NULL;
    
}

int main(int argc, char const *argv[])
{
    sem_init(sem,0,0);

    pthread_t write,read;
    pthread_create(&write,NULL,write_func,NULL);
    pthread_create(&read,NULL,read_func,NULL);

    pthread_join(write,NULL);
    pthread_join(read,NULL);
    return 0;
}
